<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <script src="../../js/load.js"></script>
    <style>
        #fileList {
            width: 100%;
        }

        .dirLevel {
            cursor: pointer;
            text-decoration: underline
        }

        .dirLevel:hover {
            color: blue;
        }



    </style>
</head>

<body>
<div style="width: 100%;height: 100%;">
    <div id="fileList">
        <div style="width: 100%;height: 50px;display: flex;flex-direction: row;justify-items: left;align-items: center">
            <i class="layui-icon layui-icon-home" onclick="ChangeNavPrefix(-1)"
               style="margin-right: 10px;margin-left:20px;cursor: pointer;font-size: 25px"></i>
            <span class="layui-breadcrumb" id="prefixNav">

            </span>
        </div>
        <div class="layui-fluid">
            <table class="layui-table" lay-data="{id: 'datagrid',height:'full'}" lay-filter="datagrid">
                <thead>
                <tr>
                    <th lay-data="{fixed: 'right', toolbar: '#name'}">名称</th>
                    <th lay-data="{field:'createDate',width:180,align:'center'}">创建时间</th>
                    <th lay-data="{field:'lastModifyDate',width:180,align:'center'}">修改时间</th>
                    <th lay-data="{fixed: 'right', width:180, align:'center', toolbar: '#op'}">操作</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="name">
    {{#  if(d.checkDir){ }}
    <span class="layui-icon layui-icon-table layui-font-24"></span><span style="margin-left: 10px;" class="dirLevel"
                                                                         onclick="ChangeFilePrefix('{{d.fileName}}')">{{d.fileName}}</span>
    {{#  } else { }}
    <span class="layui-icon layui-icon-file layui-font-24"></span><span style="margin-left: 10px">{{d.fileName}}</span>
    {{#  } }}
</script>
<script type="text/html" id="op">
    {{#  if(!d.checkDir){ }}
    <button class="layui-btn layui-btn-sm" lay-event="HandleDetail"><i
            class="layui-icon layui-icon-search layui-font-12"></i>查看
    </button>
    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="HandleDownLoad"><i
            class="layui-icon layui-icon-download-circle layui-font-12"></i>下载
    </button>
    {{#  } }}
</script>
</body>
</html>
<script>
    var projectID = GetUrlParam("projectID")
    var prefixList = []
    var element = layui.element;
    $(function () {
        BindTableData();
    })

    function BindTableData() {
        var param = {
            "prefix": GetFilePrefix(),
            "projectID":projectID
        }
        BindTable("datagrid", "api/pfmanage/list", param, function (result) {

        }, false);
    }

    function GetFilePrefix() {
        var prefix = "";
        for (var i = 0; i < prefixList.length; i++) {
            if (i == prefix.length - 1) {
                prefix += prefixList[i];
            } else {
                prefix += prefixList[i] + "/";
            }
        }
        return prefix;
    }

    function ChangeFilePrefix(fileName) {
        prefixList.push(fileName);
        RenderBread();
        BindTableData();
    }

    function ChangeNavPrefix(index) {
        prefixList = prefixList.slice(0, parseInt(index) + 1);
        RenderBread();
        BindTableData();
    }

    function RenderBread() {
        var html = "";
        for (var i = 0; i < prefixList.length; i++) {
            var prefixString = prefixList[i];
            html += " <a href='#' onclick=ChangeNavPrefix('" + i + "')>" + prefixString + "</a>"
        }
        $("#prefixNav").html(html);
        layui.element.render();
    }

    function HandleDetail(RowData) {
        OpenDialog('查看文件', "pages/pfmanage/projectfile_detail.html?prefix=" + encodeURIComponent(GetFilePrefix()) + "&fileName=" + encodeURIComponent(RowData.fileName)+"&projectID="+projectID, 1366, 768)
    }

    function HandleDownLoad(RowData) {
        var url = GetRootPath() + "api/pfmanage/download?prefix=" + encodeURIComponent(GetFilePrefix()) + "&fileName=" + encodeURIComponent(RowData.fileName)+"&projectID="+projectID;
        window.top.open(url);
    }



</script>